﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using CoreEx.Database.Metadata;
using CoreEx.Database.Query;

namespace CoreEx.Database.Linq
{
    /// <summary>
    /// Represents a projection target (table) from witch columns may be projected.
    /// </summary>
    public interface IProjectionTarget_old
    {
        /// <summary>
        /// Gets or sets the target member for this <see cref="IProjection"/>
        /// </summary>
        /// <remarks>
        /// The member may be a <see cref="Type"/> or a <see cref="PropertyInfo"/> instance.
        /// </remarks>        
        MemberInfo Member { get; set; }

        /// <summary>
        /// Gets or sets the alias used for this projection
        /// </summary>
        string Alias { get; set; }

        /// <summary>
        /// Gets the map that contains the connection between a projected column in the query and a member (property).
        /// </summary>
        IDictionary<MemberInfo, string> MemberMap { get; }

        /// <summary>
        /// Gets or sets the <see cref="ITypeMappingInfo"/> instance that corresponds to the <see cref="Member"/>.
        /// </summary>
        ITypeMappingInfo TypeMappingInfo { get; set; }

        /// <summary>
        /// Gets or sets the <see cref="IExpression"/> needed to access the <see cref="IProjectionTarget"/>.
        /// </summary>
        IExpression DbExpression { get; set; }

        /// <summary>
        /// Gets or sets the <see cref="IExpression"/> that contains the projected columns, if any. 
        /// </summary>
        IExpression Projection { get; set; }

        /// <summary>
        /// Gets a list of column names that represents the primary key columns as they are projected from the query.
        /// </summary>
        /// <remarks>
        /// When a query joins multiple tables that have the same primary key column name, the projection will make each 
        /// primary key column unique. E.g. t0.PrimaryId, t1.PrimaryId1 
        /// </remarks>
        string[] PrimaryKeyColumnNames { get; set; }


        /// <summary>
        /// Gets or sets the parent <see cref="IProjectionTarget"/> that "owns" this projection target. 
        /// </summary>
        IProjectionTarget_old Parent { get; set; }


        /// <summary>
        /// Returns a list of <see cref="IProjectionTarget"/> instances that is "owned" by this projection target.
        /// </summary>
        IList<IProjectionTarget_old> Children { get; } 


        /// <summary>
        /// Gets the <see cref="Member"/> type.
        /// </summary>
        /// <returns></returns>
        Type GetMemberType();

    }

    ///// <summary>
    ///// Represents the result of a translated <see cref="Expression"/>
    ///// </summary>
    //public interface ITranslationResult
    //{
    //    /// <summary>
    //    /// Gets a list of <see cref="IProjectionTarget"/> instances. 
    //    /// </summary>
    //    IDictionary<MemberInfo,IProjectionTarget> ProjectionTargets { get; }

    //}

}
